﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;

namespace IToursDataService
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码和配置文件中的接口名“IGuestComments”。
    [ServiceContract]
    public interface IGuestComments
    {
        [OperationContract(Name = "GetAccountDataJson")]
        [WebGet(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetAccountData", BodyStyle = WebMessageBodyStyle.Bare)]
        List<Account> GetAccountData();

        [OperationContract]
        [WebGet(UriTemplate = "GetAccount/{age}",BodyStyle = WebMessageBodyStyle.WrappedRequest,ResponseFormat = WebMessageFormat.Json,RequestFormat = WebMessageFormat.Json)]
        Account GetAccount(string age);

        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "SaveAccount", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
        bool SaveAccount(Account account);

        [OperationContract(Name = "SendMessageJson")]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "SendMessage/{Message}", BodyStyle = WebMessageBodyStyle.Bare)]
        string SendMessage(string Message);
    }

    //[ServiceContract]
    //public interface IAccountXmlService
    //{
    //    [OperationContract(Name = "GetAccountDataXml")]
    //    [WebGet(RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, UriTemplate = "GetAccountData", BodyStyle = WebMessageBodyStyle.Bare)]
    //    List<Account> GetAccountData();

    //    [OperationContract(Name = "SendMessageXml")]
    //    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, UriTemplate = "SendMessage/{Message}", BodyStyle = WebMessageBodyStyle.Bare)]
    //    string SendMessage(string Message);
    //}

    [DataContract]
    public class Account
    {
        [DataMember]
        public string Name { get; set; }
        [DataMember]
        public int Age { get; set; }
        [DataMember]
        public string Address { get; set; }
        [DataMember]
        public string Birthday { get; set; }
        //public DateTime Birthday { get; set; }
    }

    public class MockAccount
    {
        //public static MockAccount()
        //{
        //    AccountList = new List<Account>();
        //    AccountList.Add(new Account { Name = "Bill Gates", Address = "YouYi East Road", Age = 56, Birthday = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") });
        //    AccountList.Add(new Account { Name = "Steve Paul Jobs", Address = "YouYi West Road", Age = 57, Birthday = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") });
        //    AccountList.Add(new Account { Name = "John D. Rockefeller", Address = "YouYi North Road", Age = 65, Birthday = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") });

        //}
        public static List<Account> _AccountList; 
        public static List<Account> AccountList
        {
            get
            {
                if (_AccountList==null || _AccountList.Count == 0)
                {
                    _AccountList = new List<Account>();
                    _AccountList.Add(new Account { Name = "Bill Gates", Address = "YouYi East Road", Age = 56, Birthday = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") });
                    _AccountList.Add(new Account { Name = "Steve Paul Jobs", Address = "YouYi West Road", Age = 57, Birthday = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") });
                    _AccountList.Add(new Account { Name = "John D. Rockefeller", Address = "YouYi North Road", Age = 65, Birthday = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") });
                    return _AccountList;
                }
                else
                {
                    return _AccountList;
                }
            }
        }
    }

}
